<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>梦想抓娃娃</title>
    <link rel="stylesheet"  href="src/css/base.css?__version=9.4">
    <link rel="stylesheet"  href="src/css/pages.css?__version=9.4">
    <link rel="stylesheet"  href="src/css/swiper.min.css?__version=9.4">
    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?8ed2efe5b24e14f351f4d88ba2eb3462";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

</head>
<body>
<div class="init_content" style="display: none;">
    <header class="fixed_top">
        <a href="/backpack.html" class="bplist is_loginbtn"><img src="src/img/shouyebeibao.png"></a>
        <span>梦想抓娃娃</span>
        <a href="/personal.html" class="usercenter is_loginbtn"><img src="src/img/gerenzhongxin.png"></a>
    </header>

    <div class="warp home-warp">
        <div class="swiper-container home-swiper-container">
            <div class="swiper-wrapper" id="banner"></div>
            <div class="swiper-pagination"></div>
        </div>
        <div class="scrolltext">
            <span class="notice">通知</span>
            <div class="winBox">
                <ul class="scroll" id="scroll"></ul>
            </div>
        </div>
        <section class="doll-list flex" id="getMachineList"></section>
    </div>
    <div class="rightfloat">
        <a href="/luckdraw.html" class="button luckdrawbtn"><img src="src/img/giftbtn.png">抽奖</a>
        <a href="javascript:;" class="button follow"><img src="src/img/weixinguanzhu.png">送金币</a>
        <!-- <a href="javascript:getMachineList();" class="button "><img src="src/img/huangyipi.png">换一批</a> -->
        <a href="/novice.html" class="button "><img src="src/img/noticeico.png">攻略</a>
    </div>
    <div class="fixed-bottom">
        <img class="logo" src="src/img/logo2.png?v=3">
        <a href="http://sj.qq.com/myapp/detail.htm?apkName=com.mxzhuawawa.app" class="down"><img src="src/img/lijixiazaianniu.png?v=1"></a>
    </div>
</div>
<div class="init_loading">
    <img src="src/img/page_loading.gif?v=1">
</div>
<div class="rightfixe none">
    <div class="weixinguanzhubox">
        <button class="closebtn"><img src="src/img/login-close.png"></button>
        <div class="weixincontent">
            <div class="itemc">微信关注梦想抓娃娃</div>
            <div class="itemd">首次关注即可获得<span></span>金币</div>
            <div class="img"><img src="/src/img/codeimg.jpg?v=1"></div>
            <div class="text">长按识别二维码</div>
        </div>
    </div>
</div>
<div class="activity_window">
    <div class="activity_content">
        <ul>
            <li class="item" style="display:block;">
                <div class="img"><a href="/wx_login.php"><img src="src/img/activity2.png?v=1"></a></div>
            </li>
            <li class="item">
                <div class="img"><a href="/myred.html"><img src="src/img/activity1.png"></a></div>
            </li>
        </ul>
        <button class="activity_close"><img src="src/img/activity_close.png"></button>
    </div>
</div>
<script type="text/javascript" src="src/js/jquery-1.10.1.min.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/dropload.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/init.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/swiper.min.js?__version=9.4"></script>
<script type="text/javascript" src="src/js/rem.js?__version=9.4"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/src/js/share.js?__version=9.4"></script>
<script>
    $(function(){
        if(token){
            isNewMessage(".fixed_top a.usercenter");
            fetchData("/OpenAPI/v1/user/info",{"token":token},function(data){
                if(data.error){
                    logout();
                }else{
                    user.nickname = data.nickname;
                    user.avatar = data.avatar;
                    user.coinbalance = data.coinbalance;
                    user.uid = cookieGet("uid");
                    cookieSet("coinbalance",data.coinbalance);
                }
            })
        }

        getMachineList();
        banner();
        getLastCatchtoy();
        configFn();
        var num = 0;

        function goLeft() {
            if (num == -7600) {num = 0;}
            num -= 1;
            $(".scroll").css({left: num})
        }
        var timer = setInterval(goLeft, 20);

        if(token){
            var is_register=cookieGet("is_register");
            if(is_register=="1"){
                $(".activity_window").show();
                $(".activity_window .activity_content .item").eq(1).show();
                $(".activity_window .activity_content .item").eq(0).hide();
            }else{
                $(".activity_window").hide();
            }
        }else{
            $(".activity_window").show();
            $(".activity_window .activity_content .item").eq(0).show();
            $(".activity_window .activity_content .item").eq(1).hide();
        }
    })
    $(document).on("click",".rightfloat .follow",function(){
        $(".rightfixe").removeClass("none");
    })
    $(document).on("click",".weixinguanzhubox .closebtn",function(){
        $(".rightfixe").addClass("none");
    })
    $(document).on("click",".activity_content .activity_close",function(){
        cookieRemove("is_register");
        $(".activity_window").hide();
    })
    function configFn(){
        $.ajax({
            type:'get',
            url:api_url+"/OpenAPI/v1/app/config",
            jsonp: 'callback',
            dataType:'jsonp',
            success:function(data){
                console.log(data);
                $(".weixincontent .itemd span").html(data.data.subscribeCoin);
            }
        })
    }
    function getLastCatchtoy(){
        $.ajax({
            type:'get',
            url:api_url+"/OpenAPI/v1/app/message",
            jsonp: 'callback',
            dataType:'jsonp',
            success:function(data){
                console.log(data);
                var list=data.data;
                var html='';
                for(var i=0;i<list.length;i++){
                    var temp=list[i]['template'];
                    var username=temp.replace("恭喜 %s","恭喜 "+list[i]['username']);
                    var target=username.replace("了 %s","了 <span>"+list[i]['target']+"</span>")
                    html+='<li>'+target+'</li>'
                }
                $("#scroll").html(html+html);
            }
        })
    }

    function getMachineList(){
        $.ajax({
            type:"get",
            url:api_url+"/OpenAPI/v1/ToyMachine/getMachineList",
            data:{page:1},
            jsonp: 'callback',
            dataType:'jsonp',
            beforeSend:function(){
                $("#getMachineList").html("<div style='width:100%;border-radius:5px;text-align:center;color:#666;font-size:16px;padding:100px 0;background:#fff;'>加载中...</div>");
            },
            success:function(data){
                console.log(data);
                var html="";
                var list=data.data.list;
                if(list.length>0){
                    for(var i=0;i<list.length;i++){
                        var play="";
                        if(list[i]['play_state']=='0'){
                            play='src/img/playn.png';
                        }else{
                            play='src/img/playy.png'
                        }
                        html+='<div class="doll-item indexnurl"  data-roomid="'+list[i]['machine_id']+'"><a onclick="_hmt.push([\'_trackEvent\', \'machine_id='+list[i]['machine_id']+'房间\', \'click\', \'进入房间\', 1])" href="/show.html?machine_id='+list[i]['machine_id']+'">'
                                +'<div class="doll-img">'
                                +'<img src="'+list[i]['cover']+'">'
                                +'</div>'
                                +'<div class="name-box">'
                                +'<img class="state" src="'+play+'">'
                                +'<span class="name text-beyond">'+list[i]['title']+'</span>'
                                +'</div>'
                                +'<div class="doll-money"><img src="src/img/shouyejinbi.png"><span>'+list[i]['price']+'/次</span></div>'
                                +'</a></div>';
                    }
                }else{
                    html+='<div style="width:100%;border-radius:5px;text-align:center;color:#666;font-size:16px;padding:100px 0;background:#fff;">暂无数据</div>'
                }

                $("#getMachineList").html(html);
            }
        })
    }

    function banner(){
        $.ajax({
            type:"get",
            url:api_url+"/OpenAPI/v1/app/banner",
            data:{page:1,moc:'H5',token:token},
            jsonp: 'callback',
            dataType:'jsonp',
            success:function(data){
                console.log(data);
                var html="";
                var list=data.data;
                for(var i=0;i<list.length;i++){
                    html+='<a onclick="_hmt.push([\'_trackEvent\', \'banner\', \'click\', \'活动页面\', 1])" class="swiper-slide" href="'+list[i]['url']+'"><img  data-url="'+list[i]['url']+'" src="'+list[i]['image']+'"></a>';
                }
                $("#banner").html(html);
                var swiper = new Swiper('.home-swiper-container', {
                    pagination: '.swiper-pagination',
                    slidesPerView: 'auto',
                    autoplay: 5000,
                    centeredSlides: true,
                    paginationClickable: true,
                    // spaceBetween: 10,
                    loop:true,
                    speed: 500,
                    observer:true,
                    observeParents:true,
                    autoplayDisableOnInteraction : false,
                    onSlideChangeEnd:function(swiper){}
                });
            }
        })
    }
    var masterid = getQueryString("mid");
    var recommend = getQueryString("recommend");
    if (recommend) {
        cookieSet('recommend',recommend);
    }
    if(masterid) {
        cookieSet('masterid',masterid);
    }
    if(!isLogin){
        if(cookieGet('masterid')){
            $(".fixed-bottom").hide();
        }
    }

</script>
</body>
</html>
